package com.woniuxy.hrp.provider;

import com.woniuxy.hrp.entity.Hospital;
import org.apache.ibatis.jdbc.SQL;

/**
 * @program: hrph
 * @ClassName HospitalMapperSqlProvider
 * @description:多条件查询医院动态sql
 * @author: LRW
 * @create: 2022-08-30 17:56
 * @Version 1.0
 **/
public class HospitalMapperSqlProvider {
    public static String selectHospitalByCondition(Hospital hospital) {
        String sql = new SQL() {
            {
                SELECT("*");
                FROM("hrp_hospital");
                if (hospital.getName() != null) {
                    WHERE("name = #{name}");
                }
                if (hospital.getDescription() != null) {
                    WHERE("description = #{description}");
                }
                if (hospital.getAddress() != null) {
                    WHERE("address = #{address}");
                }
                if (hospital.getTelephone() != null) {
                    WHERE("telephone = #{telephone}");
                }
            }}.toString();
        return sql;
    }

    //修改医院信息动态SQL
    public static String updateHospitalByCondition(Hospital hospital){
        String sql = new SQL(){
            {
                UPDATE("hrp_hospital");
                if (hospital.getName() != null){
                    SET("name=#{name}");
                }
                if (hospital.getAddress() != null){
                    SET("address=#{address}");
                }
                if (hospital.getDescription() != null){
                    SET("description=#{description}");
                }
                if (hospital.getTelephone() !=null){
                    SET("telephone=#{telephone}");
                }
                if (hospital.getStatus() !=null){
                    SET("status=#{status}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
        return sql;
    }
}
